#!/usr/bin/env python
# -*- coding: utf-8 -*-

# 该文件主要用于存放路径拼接的方法(主目录/个人文件夹/共享文件夹等)

from commons.config_tools import Cf
from commons.logger import log


class PathSpl:

    def __init__(self, log_n="log"):
        self.log = log_n  # 定义日志存放的文件名

    def read(self, path_option="home"):
        """
        读取配置文件中的常用的路径的值
        path_option 要取配置文件中path分组下的xx项
        return 返回所取的xx项的值
        """
        path_val = Cf().read_config_ini("path", path_option)
        return path_val

    def splice(self, path_option, user=None):
        """
        公用部分路径拼接,个人文件夹/共享文件夹等
        path_option 要取配置文件中path分组下的xx项
        user  配置文件中的用户,用于用户个人文件夹相关
        """
        path_val = self.read(path_option)
        if user and path_option == "home":  # 个人文件夹,路径拼接
            user_name = Cf().read_config_ini(user, "user_name")
            s_path = path_val + "/" + user_name
        elif path_option == "volume[0]" or path_option == "volume[1]":  # 共享文件夹,路径拼接
            s_path = path_val
        elif user is None and path_option == "home":  # home路径
            s_path = path_val
        else:
            assert 0 == 1, "该项没有可拼接的路径,请检查参数,或补充条件添加判断!"
        log(self.log).info("获取到的根路径为:%s" % s_path)
        return s_path
